#ifndef HARDWARE_HANDLING_H
#define HARDWARE_HANDLING_H
#include "sql_Connector.h"
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <string>
#include "item.h"
#include <map>
#include <Python.h>
#include <QtConcurrent\qtconcurrentrun.h>
#include <qfuture.h>
#include <qfuturewatcher.h>


class Hardware_handling
{
private:
	string cmd;
	size_t len;
	int total_price;
	// map between CashierId and the current transaction list
	map<int,map<int,int>> Transact_CID;
	// map between barcode and quantity
	map<int,int> barToquan;
	int cashier;
	enum Code{Start=12, End=14, Cancel=13, Add_item=15, Remove_item=17};
	enum ACK{END_BYTE=74, START_SUCCESS=0, START_FAIL=1, END_SUCCESS=2, CANCEL_SUCCESS=3, ADD_SUCCESS=4, BARCODE_NE=5, STOCK_NE=6 , REMOVE_SUCCESS=7, RM_BARCODE_NE=8, RM_Q_LARGE=9 , END_WARNING=10 , NOT_START_YET=11, END_FAIL=12, TOO_MUCH_MONEY=13};
public:
	Hardware_handling(void);
	Hardware_handling(char cmd_in[], size_t len_buf);
	~Hardware_handling(void);

	void set_cmd(char cmd_in[], size_t len_buf);

	// Intepret the cmd string input
	string Intepret();

	// Functions to handle different command
	string Start_command();
	string Add_command();
	string End_command();
	string Cancel_command();
	string Remove_command();
	string Not_Strt_Yet(int cId);
	// Compute the information for price display
	string to_Price_display(int pId);
	void sendSMS(string sms);
	int get_Customer_money();
private:
	// Check if cashier Id exist
	bool check_CashierId(int cashierId);
	// Check if barcode exist
	bool check_Barcode(int barcode, Item *iFind);
	// Add new item to the list
	int Put_Item_to_Map(Item *iFind,int quantity);
	// Check if the string is number
	bool is_number(const std::string& s);
	// Convert the header of cashierID or PID
	string convertDec(int number);
	// Convert the money to 6 digit
	string convert_Change(int change);
};

#endif

